package cn.com.xy.sms.sdk.ui.menu;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import java.util.Map;

import cn.com.xy.sms.sdk.ui.popu.util.UiPartInterface;
import cn.com.xy.sms.sdk.ui.popu.util.ViewManger;

public class PopMenus {
    private static final String TAG = "PopMenus";
    private PopMenus mPopMenu = null;

    public static ViewGroup bindMenuView(final View rootView, final Object data, View.OnClickListener click, final Map<String,Object> extend) {
        if (sUiInterface == null) {
            sUiInterface = ViewManger.getUiPartInterface();
        }
        try {
            return (ViewGroup)sUiInterface.doUiActionMulti(ViewManger.UIPART_ACTION_BIND_MENU, rootView,data, click, extend);
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return null;
    }

    public boolean ismIsShow() {
        if (mPopMenu != null) {
            return mPopMenu.ismIsShow();
        }
        return false;
    }

    private static UiPartInterface sUiInterface;

    public PopMenus() {
    }

    public PopMenus(Activity context, Object data, int width, int height) {
        if (sUiInterface == null) {
            sUiInterface = ViewManger.getUiPartInterface();
        }
        try {
            mPopMenu = (PopMenus) sUiInterface.doUiActionMulti(ViewManger.UIPART_ACTION_GET_POPMENU, context,
                    data, width, height);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    public PopMenus(Activity context, Object data, int width, int height, int simIndex,
            Map<String, String> extraMenuDataMap) {
        if (sUiInterface == null) {
            sUiInterface = ViewManger.getUiPartInterface();
        }

        try {
            mPopMenu = (PopMenus) sUiInterface.doUiActionMulti(ViewManger.UIPART_ACTION_GET_POPMENU, context,
                    data, width, height,simIndex,extraMenuDataMap);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    public void showAtLocation(View parent) {
        if(mPopMenu != null){
            mPopMenu.showAtLocation(parent);
        }
    }

    public void showPopupAccordingParentView() {
        if(mPopMenu != null){
            mPopMenu.showPopupAccordingParentView();
        }
    }

    public void dismiss() {
        if(mPopMenu != null){
            mPopMenu.dismiss();
        }
    }

    public void destory() {
        if(mPopMenu != null){
            mPopMenu.destory();
            mPopMenu = null;
        }
    }

    public boolean isShow() {
        if(mPopMenu != null){
            return mPopMenu.isShow();
        }
        return false;
    }

}
